package com.atguigu.jedis.demo;

import redis.clients.jedis.Jedis;

import java.util.Set;

/**
 * Created by Smexy on 2022/6/17
 */
public class JedisDemo4 {

    public static void main(String[] args) {

        //创建客户端对象
        Jedis jedis = new Jedis("hadoop104", 6379);

        jedis.auth("123456");

        jedis.sadd("numbers1","1","2","3","4");

        Set<String> numbers = jedis.smembers("numbers1");

        System.out.println(numbers);

        System.out.println(jedis.sismember("numbers1", "5"));

        //如果set类型的key不存在，返回 [] 空集合
        Set<String> set = jedis.smembers("afaefaa");

        // [] != null  [].foreach  null.foreach报错 空指针异常
        // 任意的set集合，都可以直接遍历，无需担心空指针异常
        System.out.println(set);

        //关闭客户端
        jedis.close();

    }

}
